﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace PitBull.Payment.Payson
{
    public class PaysonPaymentHelper
    {
        public string CalculateMD5Hash(string MD5String, string key)
        {
            string md5Hash;
            string completeMD5String = MD5String + key;

            ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();

            Byte[] result = md5Provider.ComputeHash(encoding.GetBytes(completeMD5String));
            md5Hash = ToHexString(result);

            return md5Hash;
        }

        private static string ToHexString(Byte[] input)
        {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < input.Length; i++)
            {
                builder.Append(input[i].ToString("x2"));
            }

            return builder.ToString();
        }
    }
}
